<?php

require_once 'util/class.daofactory.php';
require_once 'util/class.idservice.php';

class NoteService {
	
	public function publishNote($userId,$note,$pics,$tags,$src,$ip) {
		$result = array();
		if(!is_int($userId) || $userId<=0
				|| !$note || strlen($note)>Constants::$MAX_NOTE_LEN
				|| !$tags || count($tags)==0 ) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		// step1, get note id
		$noteId = IdService::getNextId('note');
		if($noteId<0) {
			$result['status']=$noteId;
			return $result;
		}
		$ts = time();
		
		// parse pics
		$picUrls = null;
		if($pics && strlen($pics)>0) {
			$tmpPics=explode('_', $pics);
			$len=count($tmpPics);
			$picUrls=array();
			for($i=0; $i<$len; $i+=3)
				$picUrls[]=$tmpPics[$i];
		}
		
		// step2, save this note
		global $noteDao;
		$resultId=$noteDao->addNote($noteId, $userId, Constants::$NOTE_TYPE_PUBLIC,
				$note, $picUrls, $tags, $src, $ip, $ts);
		
		if($resultId<0) {
			$result['status']=$resultId;
			return $result;
		}
		
		// step3, update the lastNoteId of user
		global $userDao;
		$userDao->updateField($userId, 'lastNid', $noteId);
		
		// step4, update outbox
		global $outboxDao;
		$outboxId=IdService::getNextIdWithSplitId('outbox', $userId);
		if($outboxId>0) 
			$outboxDao->addOutboxItem($outboxId, $userId, $noteId,
					Constants::$OUTBOX_TYPE_PUBLIC, $ts);
		
		// step5, update inbox of user
		global $inboxDao;
		$inboxId=IdService::getNextIdWithSplitId('inbox', $userId);
		if($inboxId>0)
			$inboxDao->addInboxItem($inboxId, $userId, $noteId, $userId,
					Constants::$INBOX_TYPE_PUBLIC, $ts);
		
		// step6, async process other steps
		$this->asyncProcessPublishNote($userId, $noteId, $tags, $tmpPics, $ts);
		
		$result['status']=Constants::$SUCCESS;
		$result['data']=array('noteId'=>$noteId);
		return $result;
	}
	
	// TODO need aync process
	public function asyncProcessPublishNote($userId, $noteId, $tags, $pics, $timestamp) {
		
		// step1 dispath noteid to followees inbox and update followees notify
		$this->updateFolloweeInboxAndNotify($userId, $noteId, $timestamp);
		
		global $tagListDao;
		global $discoveryDao;
		// step2 add noteid to discovery list
		$picNum=count($pics)/3;
		if($picNum>0) {
			$sizeX=0;
			$sizeY=0;
			$picTypes = array();
			$type=0;
			for($i=0; $i<$picNum; $i++) {
				$sizeX=intval($pics[$i*3+1]);
				$sizeY=intval($pics[$i*3+2]);
				$type=$this->getPictureType($sizeX, $sizeY);
				$picTypes[$type]=$pics[$i*3];
			}
			
			$discoveryItems = array();
			$item=null;
			$itemNum=count($picTypes);
			$endId=IdService::getNextIdRange('discovery', $itemNum);
			$startId=$endId-$itemNum;
			foreach($picTypes as $k=>$v) {
				$item=array('_id'=>$startId, 'tp'=>$k, 'nid'=>$noteId, 'picUrl'=>$v, 'ts'=>$timestamp);
				$discoveryItems[]=$item;
				$startId++;
			}
			$discoveryDao->batchAddDiscoveryItems($discoveryItems);
		}
		
		
		// step3 add noteid to tags list
		$tagNum=count($tags);
		if($tagNum>0) {
			$endId = IdService::getNextIdRange('taglist', $tagNum);
			$startId=$endId-$tagNum;
			
			$tagItems=array();
			$item=null;
			for($i=$startId; $i<$endId; $i++) {
				$item = array('_id'=>$i, 'tid'=>$tags[$i-$startId], 'nid'=>$noteId, 'ts'=>$timestamp);
				$tagItems[]=$item;
			}
			$tagListDao->batchAddTagListItems($tagItems);
		}
	}
	
	public function forwardNote($userId, $note, $replyNoteId, $replyUserId, $src, $ip) {
		$result = array();
		if(!is_int($userId) || $userId<=0
				|| !$note || strlen($note)>Constants::$MAX_NOTE_LEN
				|| !is_int($replyNoteId) || $replyNoteId<=0
				|| !is_int($replyUserId) || $replyUserId<=0) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		// step1, get note id
		$noteId = IdService::getNextId('note');
		if($noteId<0) {
			$result['status']=$noteId;
			return $result;
		}
		$ts = time();
		
		global $noteDao;
		global $commentDao;
		global $userDao;
		global $inboxDao;
		global $outboxDao;
		
		// step2, save this note as reply note
		$resultId=$noteDao->addNote($noteId, $userId, Constants::$NOTE_TYPE_PUBLIC,
				$note, null, null, $src, $ip, $ts, $replyUserId, $replyNoteId);
		if($resultId<0) {
			$result['status']=$resultId;
			return $result;
		}
		
		// step3, save this note as comment and update comment num
		$commentId=IdService::getNextIdWithSplitId('comments', $replyNoteId);
		if($commentId>0) {
			$commentDao->addComment($commentId, $userId, $replyNoteId, $note,
					$ts, $src);
			
			$noteDao->updateCommentNum($replyNoteId, 1);
		}
		
		// step4, update the last noteid of user
		$userDao->updateField($userId, 'lastNid', $noteId);
		
		// step5, update the outbox
		$outboxId=IdService::getNextIdWithSplitId('outbox', $userId);
		if($outboxId>0)
			$outboxDao->addOutboxItem($outboxId, $userId, $noteId,
					Constants::$OUTBOX_TYPE_REPLY, $ts);
		
		// step6, update the inbox
		$inboxId=IdService::getNextIdWithSplitId('inbox', $userId);
		if($inboxId>0)
			$inboxDao->addInboxItem($inboxId, $userId, $noteId, $userId,
					Constants::$INBOX_TYPE_REPLY, $ts);
		
		// step7, async process other steps
		$this->asyncProcessForwardNote($userId, $noteId, $replyUserId, $ts);
		
		$result['status']=Constants::$SUCCESS;
		$result['data']=array('noteId'=>$noteId);
		return $result; 
		
	}
	
	public function asyncProcessForwardNote($userId, $noteId, $replyUserId, $timestamp) {
	
		// step1, dispath noteid to followees inbox and update followees notify
		$this->updateFolloweeInboxAndNotify($userId, $noteId, $timestamp);
		// step2, update replyUser inbox and notify
		global $inboxDao;
		global $notifyDao;
		$inboxId=IdService::getNextIdWithSplitId('inbox', $replyUserId);
		if($inboxId>0) {
			$inboxDao->addInboxItem($inboxId, $replyUserId,
					$noteId, $userId, Constants::$INBOX_TYPE_REPLY, 
					$timestamp);
			
			$notifyDao->addNotify($replyUserId, array('reply'=>1));
		}
	}
	
	public function commentNote($userId, $note, $replyUserId, $replyNoteId, $src, $ip) {
		$result = array();
		if(!is_int($userId) || $userId<=0
				|| !$note || strlen($note)>Constants::$MAX_NOTE_LEN
				|| !is_int($replyNoteId) || $replyNoteId<=0
				|| !is_int($replyUserId) || $replyUserId<=0) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		// step1, get next commentId
		$commentId = IdService::getNextIdWithSplitId('comments', $replyNoteId);
		if($commentId<0) {
			$result['status']=$commentId;
			return $result;
		}
		$ts = time();
		
		global $commentDao;
		global $noteDao;
		global $outboxDao;
		global $inboxDao;
		global $notifyDao;
		
		// step2, save comment
		$commentDao->addComment($commentId, $userId, $replyNoteId, $note,
				$ts, $src);
		// step3, update comment num of the note
		$cmtNum=$noteDao->updateCommentNum($replyNoteId, 1);
		// step4, add comment to outbox of commentor
		$outboxId = IdService::getNextIdWithSplitId('outbox', $userId);
		if($outboxId>0) {
			$outboxDao->addOutboxItem($outboxId, $userId, $replyNoteId,
					Constants::$OUTBOX_TYPE_COMMENT, $ts);
		}
		// step5, update notify to user be commented
		$notifyDao->addNotify($replyUserId, array('comment'=>1));
		// step6, add inbox to user be commented
		$inboxId = IdService::getNextIdWithSplitId('inbox', $replyUserId);
		if($inboxId>0) {
			$inboxDao->addInboxItem($inboxId, $replyUserId, $replyNoteId, $userId,
					Constants::$INBOX_TYPE_COMMENT, $ts);
		}
		
		$result['status']=Constants::$SUCCESS;
		$result['data']=array('noteId'=>$replyNoteId, 'commentId'=>$commentId, 'commentNum'=>$cmtNum);
		return $result;
	}
	
	public function likeNote($userId, $replyUserId, $replyNoteId, $src, $ip) {
		$result = array();
		if(!is_int($userId) || $userId<=0
				|| !is_int($replyNoteId) || $replyNoteId<=0
				|| !is_int($replyUserId) || $replyUserId<=0) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		// step1, get next favrioteId
		$favoriteId = IdService::getNextIdWithSplitId('favriotes', $replyNoteId);
		if($favoriteId<0) {
			$result['status']=$favoriteId;
			return $result;
		}
		$ts = time();
		
		global $favoriteDao;
		global $noteDao;
		global $outboxDao;
		global $inboxDao;
		global $notifyDao;
		
		// step2, save favriote
		$favoriteDao->addFavorite($favoriteId, $userId, $replyNoteId, $ts, $src);
		// step3, update favriote num of the note
		$favNum=$noteDao->updateFavoriteNum($replyNoteId, 1);
		// step4, add favriote to outbox of favriote user
		$outboxId = IdService::getNextIdWithSplitId('outbox', $userId);
		if($outboxId>0) {
			$outboxDao->addOutboxItem($outboxId, $userId, $replyNoteId,
					Constants::$OUTBOX_TYPE_LIKE, $ts);
		}
		// step5, update notify to user be favrioted
		$notifyDao->addNotify($replyUserId, array('like'=>1));
		// step6, add inbox to user be do favriote
		$inboxId = IdService::getNextIdWithSplitId('inbox', $replyUserId);
		if($inboxId>0) {
			$inboxDao->addInboxItem($inboxId, $replyUserId, $replyNoteId, $userId,
					Constants::$INBOX_TYPE_LIKE, $ts);
		}
		
		$result['status']=Constants::$SUCCESS;
		$result['data']=array('noteId'=>$replyNoteId, 'favoriteId'=>$favoriteId, 'favoriteNum'=>$favNum);
		return $result;
	}
	
	public function sendPrivateMessage($fromUserId, $toUserId, $message, $src, $ip) {
		$result = array();
		if(!is_int($fromUserId) || $fromUserId<=0
				|| !$toUserId || !is_int($toUserId) || $toUserId<=0
				|| !$message || strlen($message)==0 || strlen($message)>Constants::$MAX_NOTE_LEN ) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		// step1, get next noteId
		$noteId = IdService::getNextId('note');
		if($noteId<0) {
			$result['status']=$noteId;
			return $result;
		}
		$ts = time();
		
		global $noteDao;
		global $privateboxDao;
		global $notifyDao;
		// step2, save the message
		$noteDao->addNote($noteId, $fromUserId, Constants::$NOTE_TYPE_PRIVATE, $message,
				null, null, $src, $ip, $ts, $toUserId);
		
		// step3, update privatebox of sender
		$privateboxId = IdService::getNextIdWithSplitId('privatebox', $fromUserId);
		if($privateboxId>0) {
			$privateboxDao->addItem($privateboxId, $fromUserId, $noteId, $toUserId,
					Constants::$PRIVATEBOX_TYPE_SEND, $ts);
		}
		// step4, update privatebox of receiver
		$privateboxId = IdService::getNextIdWithSplitId('privatebox', $toUserId);
		if($privateboxId>0) {
			$privateboxDao->addItem($privateboxId, $toUserId, $noteId, $fromUserId,
					Constants::$PRIVATEBOX_TYPE_RECV, $ts);
		}
		// step5, update notify of receiver
		$notifyDao->addNotify($toUserId, array('private'=>1));
		$result['status']=Constants::$SUCCESS;
		$result['data']=array('messageId'=>$noteId);
		return $result;
	}
	
	public function getPrivateMessages($userId, $pageIndex, $sinceNoteId) {
		$result = array();
		if(!is_int($userId) || $userId<0
				|| !is_int($pageIndex) || $pageIndex<0
				|| !is_int($sinceNoteId) || $sinceNoteId<0 ) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		global $privateboxDao;
		// step1, get the privatebox of user
		$list = $privateboxDao->getList($userId, Constants::$PRIVATEBOX_TYPE_ALL, 
					Constants::$PRIVATE_PAGE_SIZE, $sinceNoteId);
		if(!$list || count($list==0)) {
			$result['status']=Constants::$SUCCESS;
			$result['data']=array('pageIndex'=>$pageIndex, 'messages'=>array());
		}
		
		
		// step2, get message info for the list
		$noteList=array();
		$noteInfo=null;
		$rlyUserInfo=null;
		foreach ($list as $message) {
			$noteInfo=$this->getDisplayedNote($message['nid']);
			if(!$noteInfo)
				continue;
			
			if(array_key_exists('rlyUid', $noteInfo)) {
				$rlyUserInfo = $this->getDisplayUserInfo($noteInfo['rlyUid']);
				$noteInfo['rlyNick']=$rlyUserInfo['nick'];
				$noteInfo['rlyAvatar']=$rlyUserInfo['avatar'];
			}
			
			$noteList[]=$noteInfo;
		}
		
		$result['status']=Constants::$SUCCESS;
		$result['data']=array('pageIndex'=>$pageIndex, 'messages'=>$noteList);
		return $result;
	}

	public function getRecentPrivateMessagesRecord($userId) {
		$result = array();
		if(!is_int($userId) || $userId<0 ) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		global $privateboxDao;
		// step1, get recent record of user
		$list = $privateboxDao->getRecentRecord($userId);
		if(!$list || count($list==0)) {
			$result['status']=Constants::$SUCCESS;
			$result['data']=array();
		}
		
		
		// step2, get message info for the list
		$noteList=array();
		$noteInfo=null;
		$userInfo=null;
		foreach ($list as $message) {
			$noteInfo=$this->getDisplayedNote($message['nid']);
			if(!$noteInfo)
				continue;
			$userInfo=$this->getDisplayUserInfo($message['ouid']);
			if(!$noteInfo)
				continue;
			
			$noteList[]=array('user'=>$userInfo, 'note'=>$noteInfo);
		}
		
		$result['status']=Constants::$SUCCESS;
		$result['data']=$noteList;
		return $result;
	}

	public function getAllPrivateMessagesRecord($userId, $otherUserId) {
		$result = array();
		if(!is_int($userId) || $userId<0 || !is_int($otherUserId) || $otherUserId<0) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		global $privateboxDao;
		// step1, get recent record of user
		$list = $privateboxDao->getAllRecord($userId, $otherUserId);
		if(!$list || count($list==0)) {
			$result['status']=Constants::$SUCCESS;
			$result['data']=array();
		}
		
		
		// step2, get message info for the list
		$noteList=array();
		$noteInfo=null;
		$userInfo=null;
		foreach ($list as $message) {
			$noteInfo=$this->getDisplayedNote($message['nid']);
			if(!$noteInfo)
				continue;

			if(array_key_exists('rlyUid', $noteInfo)) {
				$rlyUserInfo = $this->getDisplayUserInfo($noteInfo['rlyUid']);
				$noteInfo['rlyNick']=$rlyUserInfo['nick'];
				$noteInfo['rlyAvatar']=$rlyUserInfo['avatar'];
			}
			
			$noteList[]=$noteInfo;
		}
		
		$result['status']=Constants::$SUCCESS;
		$result['data']=$noteList;
		return $result;
	}
	
	
	public function getFriendsTimeline($userId, $pageIndex, $sinceNoteId) {
		$result = array();
		if(!is_int($userId) || $userId<=0
				|| !is_int($pageIndex) || $pageIndex<0
				|| !is_int($sinceNoteId) || $sinceNoteId<0 ) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		global $inboxDao;
		// step1, get id list from user inbox
		$inboxList = $inboxDao->getInboxList($userId, Constants::$INBOX_TYPE_PUBLIC, 
				Constants::$NOTE_PAGE_SIZE, $sinceNoteId);
		
		if(!$inboxList || count($inboxList)==0) {
			$result['status']=Constants::$SUCCESS;
			$result['data']=array('pageIndex'=>$pageIndex, 'notes'=>array());
			return $result;
		}
		
		// step2, get note info and user info for each id
		$notesList = array();
		$noteInfo=null;
		foreach ($inboxList as $inboxItem) {
			$noteInfo = $this->getDisplayedNote($inboxItem['nid']);
			if(!$noteInfo)
				continue;
			$noteInfo['type']=0;
			if($noteInfo['rlyNid']>0) {
				$noteInfo['reply'] = $this->getDisplayedNote($noteInfo['rlyNid']);
				$noteInfo['type']=1;
			}
			
			$notesList[]=$noteInfo;
		}
		
		
		// return the data
		$result['status']=Constants::$SUCCESS;
		$result['data']=array('pageIndex'=>$pageIndex, 'notes'=>$notesList);
		return $result;
	}
	
	public function getPublicTimeline($userId, $pageNum, $sinceNoteId, $type) {
		
	}
	
	public function getUserPublicTimeline($userId, $queryUserId, $pageIndex, $sinceNoteId) {
		$result = array();
		if(!is_int($userId) || $userId<=0
				|| !is_int($queryUserId) || $queryUserId<0
				|| !is_int($pageIndex) || $pageIndex<0
				|| !is_int($sinceNoteId) || $sinceNoteId<0 ) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		// step1, get the public id list from the outbox of queryUser id
		global $outboxDao;
		$outboxList = $outboxDao->getOutboxList($userId, Constants::$OUTBOX_TYPE_PUBLIC,
				Constants::$NOTE_PAGE_SIZE, $sinceNoteId);
		
		if(!$outboxList || count($outboxList)==0) {
			$result['status']=Constants::$SUCCESS;
			$result['data']=array('pageIndex'=>$pageIndex, 'notes'=>array());
			return $result;
		}
		
		// step2, get note info and user info for each id
		global $noteDao;
		$notesList = array();
		$noteInfo=null;
		$userInfo=$this->getDisplayUserInfo($userId);
		foreach ($outboxList as $outboxItem) {
			$noteInfo = $noteDao->getNoteForRead($outboxItem['nid']);
			if(!$noteInfo)
				continue;
			
			$noteInfo['type']=0;
			$noteInfo['nick']=$userInfo['nick'];
			$noteInfo['avatar']=$userInfo['avatar'];
			if($noteInfo['rlyNid']>0) {
				$noteInfo['reply'] = $this->getDisplayedNote($noteInfo['rlyNid']);
				$noteInfo['type']=1;
			}
		
			$notesList[]=$noteInfo;
		}
		
		// step3, return result
		$result['status']=Constants::$SUCCESS;
		$result['data']=array('pageIndex'=>$pageIndex, 'notes'=>$notesList);
		return $result;
	}
	
	public function getUserAllTimeline($userId, $pageIndex, $sinceTimestamp) {
		
		$result = array();
		if(!is_int($userId) || $userId<=0
				|| !is_int($pageIndex) || $pageIndex<0
				|| !is_int($sinceTimestamp) || $sinceTimestamp<0 ) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		// step1, get all id list of user
		global $outboxDao;
		$outboxList = $outboxDao->getOutboxListByTimestamp($userId, Constants::$OUTBOX_TYPE_ALL,
				Constants::$NOTE_PAGE_SIZE, $sinceTimestamp);
		
		if(!$outboxList || count($outboxList)==0) {
			$result['status']=Constants::$SUCCESS;
			$result['data']=array('pageIndex'=>$pageIndex, 'notes'=>array());
			return $result;
		}
		
		// step2, get note info and user info for each id, do different actoin for different type
		global $noteDao;
		global $commentDao;
		global $favoriteDao;
		$notesList = array();
		$noteInfo=null;
		$userInfo=$this->getDisplayUserInfo($userId);;
		$type=-1;
		foreach ($outboxList as $outboxItem) {
			$type = $outboxItem['tp'];
			if($type==0 || $type==1) {
				$noteInfo = $noteDao->getNoteForRead($outboxItem['nid']);
				if(!$noteInfo)
					continue;
				
				$noteInfo['type']=0;
				$noteInfo['nick']=$userInfo['nick'];
				$noteInfo['avatar']=$userInfo['avatar'];
				if($noteInfo['rlyNid']>0) {
					$noteInfo['reply'] = $this->getDisplayedNote($noteInfo['rlyNid']);
					$noteInfo['type']=1;
				}
			} else if($type==2) {
				$comment = $commentDao->getComment($outboxItem['uid'], $outboxItem['nid'], $outboxItem['ts']);
				if(!$comment)
					continue;
				
				$noteInfo=array('_id'=>$comment['_id'], 'type'=>2, 'nick'=>$userInfo['nick'],
						'avatar'=>$userInfo['avatar'], 'note'=>$comment['note'], 'ts'=>$comment['ts']);
				$noteInfo['reply']=$this->getDisplayedNote($comment['nid']);
			} else if($type==3) {
				$favorite = $favoriteDao->getFavorite($outboxItem['uid'], $outboxItem['nid'], $outboxItem['ts']);
				if(!$favorite)
					continue;
				
				$noteInfo=array('_id'=>$favorite['_id'], 'type'=>3, 'nick'=>$userInfo['nick'],
						'avatar'=>$userInfo['avatar'], 'ts'=>$favorite['ts']);
				$noteInfo['reply']=$this->getDisplayedNote($favorite['nid']);
			} else 
				continue;
		
			$notesList[]=$noteInfo;
		}
		
		// step3, return data
		$result['status']=Constants::$SUCCESS;
		$result['data']=array('pageIndex'=>$pageIndex, 'notes'=>$notesList);
		return $result;
	}
	
	public function getNoteComments($noteId, $pageIndex, $sinceCommentId) {
		
		$result = array();
		if(!is_int($noteId) || $noteId<=0
				|| !is_int($pageIndex) || $pageIndex<0
				|| !is_int($sinceCommentId) || $sinceCommentId<0 ) {
			$result['status']=Constants::$ERROR_INVALID_ARGS;
			return $result;
		}
		
		// step1, get the comment id list
		global $commentDao;
		$commentList = $commentDao->getCommentList($noteId, Constants::$COMMENT_PAGE_SIZE, $sinceCommentId);
		if($commentList==null) {
			$result['status']=Constants::$SUCCESS;
			$result['data']=array('pageIndex'=>$pageIndex, 'noteId'=>$noteId, 'comments'=>array());
			return $result;
		}
		
		// step2, get the user info for comment
		$userInfo=null;
		$len = count($commentList);
		$commentItem=null;
		for ($i=0; $i<$len; $i++) {
			$commentItem= & $commentList[$i];
			$userInfo = $this->getDisplayUserInfo($commentItem['uid']);
			$commentItem['nick']=$userInfo['nick'];
			$commentItem['avatar']=$userInfo['avatar'];
		}
		// step3, return data
		$result['status']=Constants::$SUCCESS;
		$result['data']=array('pageIndex'=>$pageIndex, 'noteId'=>$noteId, 'comments'=>$commentList);
		return $result;
	}
	
	public function getDisplayedNote($noteId) {
		global $noteDao;
		$noteInfo = $noteDao->getNoteForRead($noteId);
		if(!$noteInfo)
			return null;
		
		// get poster display user info
		$postUserInfo = $this->getDisplayUserInfo($noteInfo['uid']);
		$noteInfo['nick']=$postUserInfo['nick'];
		$noteInfo['avatar']=$postUserInfo['avatar'];
		return $noteInfo;
	}
	
	private function getDisplayUserInfo($userId) {
		global $userDao;
		$userInfo = $userDao->getUserDisplayInfo($userId);
		if($userInfo) {
			if(!array_key_exists('avatar', $userInfo))
				$userInfo['avatar']=Constants::$DEFAULT_AVATAR;
			return $userInfo;
		}
			
		return Constants::$DEFAULT_USER_DISPLAY_INFO;
	}
	

	private function getPictureType($sizeX, $sizeY) {
		return 0;
	}
	
	private function updateFolloweeInboxAndNotify($userId, $noteId, $timestamp) {
		
		global $relationDao;
		global $inboxDao;
		global $notifyDao;
		
		$followees = $relationDao->getFollowees($userId);
		if($followees || count($followees)>0) {
			$inboxId=0;
			foreach ($followees as $id) {
				$inboxId=IdService::getNextIdWithSplitId('inbox', $id);
				if($inboxId<0)
					continue;
		
				$inboxDao->addInboxItem($inboxId, $id, $noteId, $userId,
						Constants::$INBOX_TYPE_PUBLIC, $timestamp);
		
				$notifyDao->addNotify($id, array('message'=>1));
			}
		}
	}
}